def generatePermutations(nums, current, result, k):
    if len(nums) == 0:
        result.append(current)
        return

    for i in range(len(nums)):
        num = nums[i]
        newNums = nums[:i] + nums[i+1:]
        generatePermutations(newNums, current + str(num), result, k)

        if len(result) == k:
            return

def main():
    n = int(input())
    k = int(input())
    
    if n == 1:
        print("1")
        return
    
    nums = [i+1 for i in range(n)]
    result = []
    
    generatePermutations(nums, "", result, k)
    
    result.sort()
    print(result[k-1])

if __name__ == "__main__":
    main()